package by.kniazhych.core.data.game {
	
	/**
	 * ...
	 * @author Boutylin Mikhail
	 */
	
	import by.kniazhych.core.constants.PeaceType;
	import by.kniazhych.core.constants.UserColor;
	import by.kniazhych.core.events.GameEvent;
	import by.vaukalak.core.data.Data;
	import flash.geom.Point;
	
	[Event(name="peaceMoved", type="by.kniazhych.core.events.GameEvent")]
	public class PeaceData extends Data{
		
		private var _figureType:uint;
		private var _position:PeacePosition;
		
		public function PeaceData(figureType:uint, position:PeacePosition) {
			super();
			_position = position;
			this._figureType = figureType;
		}
		
		//--------------------------------------------------------------------------
		//
		//  PUBLIC METHODS
		//
		//--------------------------------------------------------------------------
		
		public function setPosition(x:uint, y:uint):void {
			_position.$changePosition(x, y);
			dispatchEvent(new GameEvent(GameEvent.PEACE_MOVED, true));
		}
		
		public function changePeaceType(type:uint):void {
			_figureType = type;
			dispatchEvent(new GameEvent(GameEvent.PEACE_CHANGED));
		}
		
		//--------------------------------------------------------------------------
		//
		//  GETTERS
		//
		//--------------------------------------------------------------------------
		
		public function get figureType():uint { return this._figureType; }
		public function get position():PeacePosition { return _position; }
		public function get color():uint {
			if (PeaceType.WHITE_PEACES.indexOf(_figureType) != -1) return UserColor.WHITE;
			if (PeaceType.BLACK_PEACES.indexOf(_figureType) != -1) return UserColor.BLACK;
			return uint.MAX_VALUE;
		}
		
	}

}